<?php
namespace Kernel;

use Middleware\Auth;
use Middleware\CSRFTOKEN;
use Middleware\Env;
use Route\Route;

class Kernel
{

    public $middleware = [
        CSRFTOKEN::class,
        Env::class,
        Auth::class
    ];

    function run(){
        $request = $this->handler();
        //请求中间件 从上至下
        foreach ($this->middleware as $cls){
            $obj = new $cls();
            $request = $obj->request($request);
            if($request === false)
                exit();
        }
        //路由
        $route = new Route($request);
        $route->route();
    }

    //处理报文
    function handler(){
        $request = [];
        $request['uri'] = $_SERVER['REQUEST_URI'];
        $request['get'] = $_GET;
        $request['post'] = $_POST;
        $request['method'] = $_SERVER['REQUEST_METHOD'];
        $request['cookie'] = $_COOKIE;
        unset($_SERVER);
        return $request;
    }
}